package com.xh.lesson.controller;


import com.xh.lesson.aop.annotation.LogAnnotation;
import com.xh.lesson.entity.SysHouse;
import com.xh.lesson.service.SysHouseService;
import com.xh.lesson.utils.DataResult;
import com.xh.lesson.vo.req.HouseAddReqVo;
import com.xh.lesson.vo.req.HousePageReqVo;
import com.xh.lesson.vo.req.HouseUpdateReqVo;
import com.xh.lesson.vo.resp.PageVO;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 柴&许
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/sys")
public class SysHouseController {

    @Autowired
    private SysHouseService houseService;

    @PutMapping("/house")
    @ApiOperation(value = "更新组织信息接口")
    @LogAnnotation(title = "房屋管理",action = "更新组织信息")
    @RequiresPermissions("sys:house:update")
    public DataResult updateDept(@RequestBody @Valid HouseUpdateReqVo vo){
        houseService.updateHouse(vo);
        return DataResult.success();
    }


    @PostMapping("/house")
    @ApiOperation(value = "新增组织接口")
    @LogAnnotation(title = "房屋管理",action = "新增组织")
    @RequiresPermissions("sys:house:add")
    public DataResult<SysHouse> addDept(@RequestBody @Valid HouseAddReqVo vo){
        System.out.println(vo);
        DataResult<SysHouse> result=DataResult.success();
        result.setData(houseService.addHouse(vo));
        return result;
    }
    @DeleteMapping("/house/{id}")
    @ApiOperation(value = "删除组织接口")
    @LogAnnotation(title = "房屋管理",action = "删除组织")
    @RequiresPermissions("sys:house:deleted")
    public DataResult deleted(@PathVariable("id") Integer id){
        houseService.deleted(id);
        return DataResult.success();
    }


    @PostMapping("/houses")
    @ApiOperation(value = "分页获取组织信息接口")
    @LogAnnotation(title = "房屋管理",action = "分页获取组织信息")
    @RequiresPermissions("sys:house:list")
    public DataResult<PageVO<SysHouse>> pageInfo(@RequestBody HousePageReqVo vo){
        DataResult<PageVO<SysHouse>> result=DataResult.success();
        result.setData(houseService.pageInfo(vo));
        return result;
    }



}

